package tieba.core.utils.baidu;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.MessageDigest;

public class j {
	private static final char[] h = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
			65, 66, 67, 68, 69, 70 };

	public static String a(String paramString) {
		try {
			String str = a(new ByteArrayInputStream(
					paramString.getBytes("UTF-8")));
			return str;
		} catch (Exception localException) {
		}
		return null;
	}

	public static String a(InputStream paramInputStream) {
		if (paramInputStream == null)
			return null;
		try {
			byte[] arrayOfByte = new byte[1024];
			MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
			while (true) {
				int k = paramInputStream.read(arrayOfByte);
				if (k <= 0) {
					paramInputStream.close();
					return a(localMessageDigest.digest());
				}
				localMessageDigest.update(arrayOfByte, 0, k);
			}
		} catch (Exception localException) {
		}
		return null;
	}

	public static String a(byte[] paramArrayOfByte) {
		if (paramArrayOfByte == null)
			return null;
		StringBuilder localStringBuilder = new StringBuilder(
				2 * paramArrayOfByte.length);
		for (int k = 0;; k++) {
			if (k >= paramArrayOfByte.length)
				return localStringBuilder.toString();
			localStringBuilder.append(h[((0xF0 & paramArrayOfByte[k]) >>> 4)]);
			localStringBuilder.append(h[(0xF & paramArrayOfByte[k])]);
		}
	}
}
